package com.bysj.studentsystem.handler;


import com.bysj.studentsystem.vo.ResponseDataVO;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @ClassName GlobalExceptionHandler
 * @Description:
 * @Author:
 * @Date: 2024/3/8 15:23
 */

@RestControllerAdvice
public class GlobalExceptionHandler {

    // 捕获Controller抛出的运行时异常
    @ExceptionHandler(RuntimeException.class)
    public ResponseDataVO handlerNullException(RuntimeException e) {
        // 封装异常信息为 ResponseDataVO 对象
        String msg = e.getMessage();
        if (StringUtils.isEmpty(msg)) {
            msg = "系统异常，请联系管理员！";
        }
        return new ResponseDataVO<String>().fail(msg);
    }
}
